package com.rmdjzz.slmmn.controller.admin;

import com.rmdjzz.slmmn.pojo.vo.RecommendGroupVo;
import com.rmdjzz.slmmn.pojo.vo.TypeGroupVo;
import com.rmdjzz.slmmn.service.RecommendService;
import com.rmdjzz.slmmn.service.SongService;
import com.rmdjzz.slmmn.service.TypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @作者 张绍鑫
 * @创建时间 2023/5/27
 */
@Controller
@Api(tags = "管理员首页-数据分析")
@RequestMapping("/admin")
@Slf4j
public class AdminIndex {
    @Autowired
    private TypeService typeService;
    @Autowired
    private RecommendService recommendService;
    @Autowired
    private SongService songService;
    @GetMapping("/dataAnalysis")
    @ApiOperation("刷新首页数据分析")
    public String dataAnalysis(Model model){
        List<TypeGroupVo> typeGroupVos=typeService.typeGroup();
        System.out.println(typeGroupVos);
        for (TypeGroupVo typeGroupVo:typeGroupVos){
            System.out.println(typeGroupVo);
            System.out.println(typeService.getById(typeGroupVo.getTypeId()).getType());
            typeGroupVo.setType(typeService.getById(typeGroupVo.getTypeId()).getType());
        }
        model.addAttribute("typeGroupVos",typeGroupVos);

        List<RecommendGroupVo> recommendGroupVos = typeService.recommendGroup();
        for (RecommendGroupVo recommendGroupVo:recommendGroupVos){
            log.info("recommendVo:"+recommendGroupVo);
            recommendGroupVo.setRecommend(recommendService.getById(recommendGroupVo.getRecommendId()).getRecommend());
        }
        model.addAttribute("recommendGroupVos",recommendGroupVos);

        int sum=songService.sum();
        log.info("sum:"+sum);
        model.addAttribute("sumNum",sum);

        return "indexAdmin";
    }

}
